using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using Microsoft.Ink;
using UTE.InkBar;

namespace UTE.InkBar
{
	// Represents a pre-constructed toolbar for Ink enabled applications.
	// 
	// The InkToolBar enables developers to drag and drop a toolbar for controlling Ink enabled 
	// applications.  It has buttons for Pen, Highlighter, Eraser and Lasso.  It is best used with
	// Ink controls like InkPicture and InkEdit.
	// 
	// Set the Mode property to control which tool is initially selected.  To use, subscribe and handle 
	// the SettingsChanged and ModeChanged events.  SettingsChanged is fired when a Pen or Highlighter 
	// setting changed.  ModeChanged is fired when a different tool is selected.
	// 
	// Supports Windows XP visual styles and themes when used with a manifest.
	//
	// Example:
	//
	//  using System;
	//	using System.Drawing;
	//	using System.Collections;
	//	using System.ComponentModel;
	//	using System.Windows.Forms;
	//	using System.Data;
	//	using Microsoft.Ink;
	//	using Leszynski.SampleInkControls;
	//
	//	namespace Tester
	//	{
	//	 	public class TesterForm : System.Windows.Forms.Form
	//	 	{
	//			private Leszynski.SampleInkControls.InkToolBar myInkToolBar;
	//			private Microsoft.Ink.InkPicture myInkPicture;
	//			public TesterForm()
	//			{
	//				InitializeComponent();
	//			}
	//			
	//			private void InitializeComponent()
	//			{
	//				this.myInkToolBar = new Leszynski.SampleInkControls.InkToolBar();
	//				this.myInkPicture = new Microsoft.Ink.InkPicture();
	//				this.SuspendLayout();
	//				// 
	//				// myInkToolBar
	//				// 
	//				this.myInkToolBar.AccessibleRole = System.Windows.Forms.AccessibleRole.ToolBar;
	//				this.myInkToolBar.ButtonSize = new System.Drawing.Size(31, 30);
	//				this.myInkToolBar.Name = "myInkToolBar";
	//				this.myInkToolBar.Size = new System.Drawing.Size(292, 33);
	//				this.myInkToolBar.TabIndex = 0;
	//				this.myInkToolBar.ModeChanged += new System.EventHandler(this.InkToolBar_ModeChanged);
	//				this.myInkToolBar.SettingsChanged += new System.EventHandler(this.InkToolBar_SettingsChanged);
	//				// 
	//				// myInkPicture
	//				// 
	//				this.myInkPicture.Location = new System.Drawing.Point(0, 40);
	//				this.myInkPicture.MarginX = -2147483648;
	//				this.myInkPicture.MarginY = -2147483648;
	//				this.myInkPicture.Name = "myInkPicture";
	//				this.myInkPicture.Size = new System.Drawing.Size(296, 232);
	//				this.myInkPicture.TabIndex = 1;
	//				// 
	//				// TesterForm
	//				// 
	//				this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
	//				this.ClientSize = new System.Drawing.Size(292, 266);
	//				this.Controls.AddRange(new System.Windows.Forms.Control[] 
	//				{
	//					this.myInkPicture,
	//					this.myInkToolBar});
	//					this.Load += new System.EventHandler(this.TesterForm_Load);
	//					this.ResumeLayout(false);
	//				}
	//			}
	//			[STAThread]
	//			static void Main() 
	//			{
	//				Application.Run(new TesterForm());
	//			}
	//			
	//			private void TesterForm_Load(object sender, System.EventArgs e)
	//			{
	//				//Use event handlers to initialize
	//				InkToolBar_SettingsChanged(sender, e);
	//				InkToolBar_ModeChanged(sender, e);
	//			}
	//				
	//			private void InkToolBar_SettingsChanged(object source, EventArgs e)
	//			{
	//				switch (this.myInkToolBar.Mode)
	//				{
	//					case InkToolBarMode.Pen:
	//					case InkToolBarMode.Highlighter:
	//						this.myInkPicture.DefaultDrawingAttributes = this.myInkToolBar.InkDrawingAttributes;
	//						break;
	//					case InkToolBarMode.Eraser:
	//						myInkPicture.EraserMode  = this.myInkToolBar.EraserAttributes.Mode;
	//						myInkPicture.EraserWidth = this.myInkToolBar.EraserAttributes.Width;
	//						break;
	//					default:
	//						break;
	//				}
	//			}
	//			
	//			private void InkToolBar_ModeChanged(object source, EventArgs e)
	//			{
	//				switch (this.myInkToolBar.Mode)
	//				{
	//					case InkToolBarMode.Eraser:
	//						myInkPicture.Selection	 = myInkPicture.Ink.CreateStrokes();
	//						myInkPicture.EditingMode = InkOverlayEditingMode.Delete;
	//						break;
	//					case InkToolBarMode.Lasso:
	//						myInkPicture.EditingMode = InkOverlayEditingMode.Select;
	//						break;
	//					default:
	//						myInkPicture.Selection	 = myInkPicture.Ink.CreateStrokes();
	//						myInkPicture.EditingMode = InkOverlayEditingMode.Ink;
	//						break;
	//				}
	//			}
	//		}
	//	}	
		
	/// <summary>
	/// Specifies the selected tool.
	/// </summary>
	public enum InkToolBarMode 
	{ 
		/// <summary>
		/// Represents a pen tool with opaque ink and small widths.
		/// </summary>
		Pen, 
		/// <summary>
		/// Represents a highlighter tool with transparent ink and large heights.
		/// </summary>
		Highlighter,
		/// <summary>
		/// Represents an eraser tool.
		/// </summary>
		Eraser, 
		/// <summary>
		/// Represents a flexible selection tool.
		/// </summary>
		Lasso 
	};
	
	/// <summary>
	/// Represents a pre-constructed toolbar for Ink enabled applications.
	/// </summary>
	[DefaultEvent("SettingsChanged")]
	[DefaultProperty("Mode")]
	[ToolboxBitmap(typeof(InkToolBar), "Images.InkToolBar.ico")]
	public class InkToolBar : System.Windows.Forms.ToolBar
	{
		#region Constants
		//
		// Pen size constants
		//
		private const float penSizeFine      = 10;
		private const float penSizeMedium    = 60;
		private const float penSizeThick     = 100;

		//
		// Eraser size constants
		//
		private const int   eraserSizeSmall  = 100;
		private const int   eraserSizeMedium = 300;
		private const int   eraserSizeLarge  = 600;
		#endregion
				
		#region	Definitions
		//
		// Mode
		//
		private InkToolBarMode m_mode;
		//
		// Highlighter transparency indicator
		//
		private bool m_useRasterOpForHighlighter;
		//
		// Point Eraser Indicator
		//
		private bool m_allowPointEraser;
		//
		// Settings Dialog
		//
		private SettingsDialog	m_settingsDialog;
		//
		// Attributes
		//
		private Microsoft.Ink.DrawingAttributes m_drawingAttributes;
		private Microsoft.Ink.DrawingAttributes m_penAttributes;
		private Microsoft.Ink.DrawingAttributes m_highlighterAttributes;
		private ErasingAttributes				m_eraserAttributes;
		//
		// ToolBar Buttons
		//
		private System.Windows.Forms.ToolBarButton m_btnPen;
		private System.Windows.Forms.ToolBarButton m_btnHighlighter;	
		private System.Windows.Forms.ToolBarButton m_btnEraser;
		private System.Windows.Forms.ToolBarButton m_btnLasso;
		//
		// Drop Down Menus
		//
		private System.Windows.Forms.ContextMenu m_menuPen;
		private System.Windows.Forms.ContextMenu m_menuHighlighter;
		private System.Windows.Forms.ContextMenu m_menuEraser;
		//
		// Menu: Pen->Color
		//
		private System.Windows.Forms.MenuItem      menuItemPenColor;
		private ColorMenuItem[] menuItemPenColors;
		private System.Windows.Forms.MenuItem      menuItemPenColorSeperator;
		private System.Windows.Forms.MenuItem      menuItemPenColorMore;
		//
		// Menu: Pen->Size
		//
		private System.Windows.Forms.MenuItem      menuItemPenSize;
		private SizeMenuItem[]  menuItemPenSizes;		
		private System.Windows.Forms.MenuItem      menuItemPenSizeSeperator;
		private System.Windows.Forms.MenuItem      menuItemPenSizeMore;
		//
		// Menu: Pen->Tip
		//
		private System.Windows.Forms.MenuItem menuItemTip;
		private System.Windows.Forms.MenuItem menuItemPenTipBall;
		private System.Windows.Forms.MenuItem menuItemPenTipRectangle;
		//
		// Menu: Pen->Settings...
		//
		private System.Windows.Forms.MenuItem menuItemPenSeperator;
		private System.Windows.Forms.MenuItem menuItemPenSettings;
		//
		// Menu: Highlighter->Color
		//
		private System.Windows.Forms.MenuItem      menuItemHighlighterColor;
		private ColorMenuItem[] menuItemHighlighterColors;
		private System.Windows.Forms.MenuItem      menuItemHighlighterColorSeperator;
		private System.Windows.Forms.MenuItem      menuItemHighlighterColorMore;
		//
		// Menu: Highlighter->Settings...
		//
		private System.Windows.Forms.MenuItem menuItemHighlighterSeperator;
		private System.Windows.Forms.MenuItem menuItemHighlighterSettings;
		//
		// Menu: Eraser->Mode
		//
		private System.Windows.Forms.MenuItem menuItemEraserMode;
		private System.Windows.Forms.MenuItem menuItemEraserModeStroke;
		private System.Windows.Forms.MenuItem menuItemEraserModePoint;
		//
		// Menu: Eraser->Size
		//
		private System.Windows.Forms.MenuItem menuItemEraserSize;
		private System.Windows.Forms.MenuItem menuItemEraserSizeSmall;
		private System.Windows.Forms.MenuItem menuItemEraserSizeMedium;
		private System.Windows.Forms.MenuItem menuItemEraserSizeLarge;
		//
		// Image Lists
		//
		private System.Windows.Forms.ImageList m_sizeImages;
		private System.Windows.Forms.ImageList m_colorImages;
		private System.Windows.Forms.ImageList m_imagesAlpha;
				        		
		private System.ComponentModel.IContainer components;
		#endregion

		#region Events
		//
		// Events
		//
		/// <summary>
		/// Occurs when any of the pen, highlighter or eraser settings change.
		/// </summary>
		[Category("Ink")]
		[Description("Occurs when any ink settings change.")]
		public event EventHandler SettingsChanged;
		/// <summary>
		/// Occurs when a different tool other than the currently selected tool is selected from the toolbar.
		/// </summary>
		[Category("Ink")]
		[Description("Occurs when the toolbar's Mode changes.")]
		public event EventHandler ModeChanged;
		/// <summary>
		/// Occurs when the Settings Dialog is opened or closed.
		/// </summary>
		[Category("Ink")]
		[Description("Occurs when the Settings Dialog's visibility changes.")]
		public event EventHandler SettingsDialogVisibleChanged;
		#endregion

		/// <summary>
		/// Initializes a new instance of the InkToolBar class.
		/// </summary>
		/// <remarks>
		/// The default <c>Mode</c> is Pen.  Set <c>Mode</c> to select a different startup tool.  
		/// Subscibe and handle the <c>SettingsChanged</c> and <c>ModeChanged</c> events.
		/// </remarks>
		public InkToolBar()
		{
			InitializeComponent();
			
			InitializeMenus();
			InitializeModes();

		}
		
		/// <summary>
		/// Initializes the button drop down menus.
		/// </summary>
		private void InitializeMenus()
		{
			this.menuItemPenColor  = new System.Windows.Forms.MenuItem();
			this.menuItemPenColors = new ColorMenuItem[3];
			for (int i=0; i < this.menuItemPenColors.Length; i++)
				this.menuItemPenColors[i]  = new ColorMenuItem();
			this.menuItemPenColorSeperator = new System.Windows.Forms.MenuItem();
			this.menuItemPenColorMore      = new System.Windows.Forms.MenuItem();

			this.menuItemPenSize  = new System.Windows.Forms.MenuItem();
			this.menuItemPenSizes = new SizeMenuItem[3];
			this.menuItemPenSizes[0] = new FineSizeMenuItem();
			this.menuItemPenSizes[1] = new MediumSizeMenuItem();
			this.menuItemPenSizes[2] = new ThickSizeMenuItem();

			this.menuItemTip             = new System.Windows.Forms.MenuItem();
			this.menuItemPenTipBall      = new System.Windows.Forms.MenuItem();
			this.menuItemPenTipRectangle = new System.Windows.Forms.MenuItem();

			this.menuItemPenSizeSeperator = new System.Windows.Forms.MenuItem();
			this.menuItemPenSizeMore      = new System.Windows.Forms.MenuItem();

			this.menuItemPenSeperator      = new System.Windows.Forms.MenuItem();
			this.menuItemPenSettings       = new System.Windows.Forms.MenuItem();
			
			this.menuItemHighlighterColor  = new System.Windows.Forms.MenuItem();
			this.menuItemHighlighterColors = new ColorMenuItem[3];
			for (int i=0; i < this.menuItemHighlighterColors.Length; i++)
				this.menuItemHighlighterColors[i]  = new ColorMenuItem();
			this.menuItemHighlighterColorSeperator = new System.Windows.Forms.MenuItem();
			this.menuItemHighlighterColorMore      = new System.Windows.Forms.MenuItem();

			this.menuItemHighlighterSeperator = new System.Windows.Forms.MenuItem();
			this.menuItemHighlighterSettings  = new System.Windows.Forms.MenuItem();

			this.menuItemEraserMode       = new System.Windows.Forms.MenuItem();
			this.menuItemEraserModeStroke = new System.Windows.Forms.MenuItem();
			this.menuItemEraserModePoint  = new System.Windows.Forms.MenuItem();

			this.menuItemEraserSize       = new System.Windows.Forms.MenuItem();
			this.menuItemEraserSizeSmall  = new System.Windows.Forms.MenuItem();
			this.menuItemEraserSizeMedium = new System.Windows.Forms.MenuItem();
			this.menuItemEraserSizeLarge  = new System.Windows.Forms.MenuItem();


			// 
			// m_menuPen
			// 
			this.m_menuPen.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItemPenColor,
																					  this.menuItemPenSize,
																					  this.menuItemTip,
																					  this.menuItemPenSeperator,
																					  this.menuItemPenSettings});
			// 
			// menuItemPenColor
			// 
			this.menuItemPenColor.Index = 0;
			this.menuItemPenColor.Text = "&Color";
			this.menuItemPenColor.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																							 this.menuItemPenColors[0],
																							 this.menuItemPenColors[1],
																							 this.menuItemPenColors[2],
																							 this.menuItemPenColorSeperator,
																							 this.menuItemPenColorMore});
			// 
			// menuItemPenColors[0]
			// 
			this.menuItemPenColors[0].RadioCheck = true;
			this.menuItemPenColors[0].Index = 0;
			this.menuItemPenColors[0].Text = "&Black";
			this.menuItemPenColors[0].Click += new System.EventHandler(this.MenuItemPenColors_Click);
			// 
			// menuItemPenColors[1]
			// 
			this.menuItemPenColors[1].RadioCheck = true;
			this.menuItemPenColors[1].Index = 1;
			this.menuItemPenColors[1].Text = "B&lue";
			this.menuItemPenColors[1].Click += new System.EventHandler(this.MenuItemPenColors_Click);
			// 
			// menuItemPenColors[2]
			// 
			this.menuItemPenColors[2].RadioCheck = true;
			this.menuItemPenColors[2].Index = 2;
			this.menuItemPenColors[2].Text = "&Red";
			this.menuItemPenColors[2].Click += new System.EventHandler(this.MenuItemPenColors_Click);
			// 
			// menuItemPenColorSeperator
			// 
			this.menuItemPenColorSeperator.Index = 3;
			this.menuItemPenColorSeperator.Text  = "-";
			// 
			// menuItemPenColorMore
			// 
			this.menuItemPenColorMore.Index = 4;
			this.menuItemPenColorMore.Text  = "&More Colors...";
			this.menuItemPenColorMore.Click += new System.EventHandler(this.MenuItemPenSettings_Click);
			// 
			// menuItemPenSize
			// 
			this.menuItemPenSize.Index = 1;
			this.menuItemPenSize.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																							this.menuItemPenSizes[0],
																							this.menuItemPenSizes[1],
																							this.menuItemPenSizes[2],
																							this.menuItemPenSizeSeperator,
																							this.menuItemPenSizeMore});
			this.menuItemPenSize.Text = "&Size";
			// 
			// menuItemPenSizes[0]
			// 
			this.menuItemPenSizes[0].RadioCheck = true;
			this.menuItemPenSizes[0].Index = 0;
			this.menuItemPenSizes[0].Text = "&Fine";
			this.menuItemPenSizes[0].Click += new System.EventHandler(MenuItemPenSizes_Click);
			// 
			// menuItemPenSizes[1]
			// 
			this.menuItemPenSizes[1].RadioCheck = true;
			this.menuItemPenSizes[1].Index = 1;
			this.menuItemPenSizes[1].Text = "&Medium";
			this.menuItemPenSizes[1].Click += new System.EventHandler(MenuItemPenSizes_Click);
			// 
			// menuItemPenSizes[2]
			// 
			this.menuItemPenSizes[2].RadioCheck = true;
			this.menuItemPenSizes[2].Index = 2;
			this.menuItemPenSizes[2].Text = "&Thick";
			this.menuItemPenSizes[2].Click += new System.EventHandler(MenuItemPenSizes_Click);
			// 
			// menuItemPenSizeSeperator
			// 
			this.menuItemPenSizeSeperator.Index = 3;
			this.menuItemPenSizeSeperator.Text  = "-";
			// 
			// menuItemPenSizeMore
			// 
			this.menuItemPenSizeMore.Index  = 4;
			this.menuItemPenSizeMore.Text   = "More &Sizes...";
			this.menuItemPenSizeMore.Click += new System.EventHandler(this.MenuItemPenSettings_Click);
			// 
			// menuItemTip
			// 
			this.menuItemTip.Index = 2;
			this.menuItemTip.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																						this.menuItemPenTipBall,
																						this.menuItemPenTipRectangle});
			this.menuItemTip.Text = "&Tip";
			// 
			// menuItemPenTipBall
			// 
			this.menuItemPenTipBall.Index      = 0;
			this.menuItemPenTipBall.Text       = "&Ball";
			this.menuItemPenTipBall.RadioCheck = true;
			this.menuItemPenTipBall.Click     += new System.EventHandler(this.MenuItemPenTip_Click);
			// 
			// menuItemPenTipRectangle
			// 
			this.menuItemPenTipRectangle.Index      = 1;
			this.menuItemPenTipRectangle.Text       = "&Rectangle";
			this.menuItemPenTipRectangle.RadioCheck = true;
			this.menuItemPenTipRectangle.Click     += new System.EventHandler(this.MenuItemPenTip_Click);
			// 
			// menuItemPenSeperator
			// 
			this.menuItemPenSeperator.Index = 3;
			this.menuItemPenSeperator.Text  = "-";
			// 
			// menuItemPenSettings
			// 
			this.menuItemPenSettings.Index  = 4;
			this.menuItemPenSettings.Text   = "&More Settings...";
			this.menuItemPenSettings.Click += new System.EventHandler(this.MenuItemPenSettings_Click);
			// 
			// m_menuHighlighter
			// 
			this.m_menuHighlighter.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																							  this.menuItemHighlighterColor,
																							  this.menuItemHighlighterSeperator,
																							  this.menuItemHighlighterSettings});
			// 
			// menuItemHighlighterColors
			// 
			this.menuItemHighlighterColor.Index = 0;
			this.menuItemHighlighterColor.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																									 this.menuItemHighlighterColors[0],
																									 this.menuItemHighlighterColors[1],
																									 this.menuItemHighlighterColors[2],
																									 this.menuItemHighlighterColorSeperator,
																									 this.menuItemHighlighterColorMore});
			this.menuItemHighlighterColor.Text = "&Color";
			// 
			// menuItemHighlighterColors[0]
			// 
			this.menuItemHighlighterColors[0].RadioCheck = true;
			this.menuItemHighlighterColors[0].Index = 0;
			this.menuItemHighlighterColors[0].Text = "&Yellow";
			this.menuItemHighlighterColors[0].Click += new System.EventHandler(this.MenuItemHighlighterColors_Click);
			// 
			// menuItemHighlighterColors[1]
			// 
			this.menuItemHighlighterColors[1].RadioCheck = true;
			this.menuItemHighlighterColors[1].Index = 1;
			this.menuItemHighlighterColors[1].Text = "&Fuchsia";
			this.menuItemHighlighterColors[1].Click += new System.EventHandler(this.MenuItemHighlighterColors_Click);
			// 
			// menuItemHighlighterColors[2]
			// 
			this.menuItemHighlighterColors[2].RadioCheck = true;
			this.menuItemHighlighterColors[2].Index = 2;
			this.menuItemHighlighterColors[2].Text = "&Lime";
			this.menuItemHighlighterColors[2].Click += new System.EventHandler(this.MenuItemHighlighterColors_Click);
			// 
			// menuItemHighlighterColorSeperator
			// 
			this.menuItemHighlighterColorSeperator.Index = 3;
			this.menuItemHighlighterColorSeperator.Text  = "-";
			// 
			// menuItemHighlighterColorMore
			// 
			this.menuItemHighlighterColorMore.Index = 4;
			this.menuItemHighlighterColorMore.Text  = "&More Colors...";
			this.menuItemHighlighterColorMore.Click += new System.EventHandler(this.MenuItemHighlighterSettings_Click);
			// 
			// menuItemHighlighterSeperator
			// 
			this.menuItemHighlighterSeperator.Index = 1;
			this.menuItemHighlighterSeperator.Text  = "-";
			// 
			// menuItemHighlighterSettings
			// 
			this.menuItemHighlighterSettings.Index  = 2;
			this.menuItemHighlighterSettings.Text   = "&More Settings...";
			this.menuItemHighlighterSettings.Click += new System.EventHandler(this.MenuItemHighlighterSettings_Click);
			// 
			// m_menuEraser
			// 
			this.m_menuEraser.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																						 this.menuItemEraserMode, 
																						 this.menuItemEraserSize});
			// 
			// menuItemEraserMode
			// 
			this.menuItemEraserMode.Index = 0;
			this.menuItemEraserMode.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																							   this.menuItemEraserModeStroke,
																							   this.menuItemEraserModePoint});
			this.menuItemEraserMode.Text = "&Mode";
			// 
			// menuItemEraserModeStroke
			// 
			this.menuItemEraserModeStroke.Index      = 0;
			this.menuItemEraserModeStroke.Text       = "&Stroke";
			this.menuItemEraserModeStroke.RadioCheck = true;
			this.menuItemEraserModeStroke.Click     += new System.EventHandler(this.MenuItemEraserMode_Click);
			// 
			// menuItemEraserModePoint
			// 
			this.menuItemEraserModePoint.Index      = 1;
			this.menuItemEraserModePoint.Text       = "&Point";
			this.menuItemEraserModePoint.RadioCheck = true;
			this.menuItemEraserModePoint.Click     += new System.EventHandler(this.MenuItemEraserMode_Click);
			// 
			// menuItemEraserSize
			// 
			this.menuItemEraserSize.Index = 1;
			this.menuItemEraserSize.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																							   this.menuItemEraserSizeSmall,
																							   this.menuItemEraserSizeMedium,
																							   this.menuItemEraserSizeLarge});
			this.menuItemEraserSize.Text = "&Size";
			// 
			// menuItemEraserSizeSmall
			// 
			this.menuItemEraserSizeSmall.Index      = 0;
			this.menuItemEraserSizeSmall.Text       = "&Small";
			this.menuItemEraserSizeSmall.RadioCheck = true;
			this.menuItemEraserSizeSmall.Click     += new System.EventHandler(this.MenuItemEraserSize_Click);
			// 
			// menuItemEraserSizeMedium
			// 
			this.menuItemEraserSizeMedium.Index      = 1;
			this.menuItemEraserSizeMedium.Text       = "&Medium";
			this.menuItemEraserSizeMedium.RadioCheck = true;
			this.menuItemEraserSizeMedium.Click     += new System.EventHandler(this.MenuItemEraserSize_Click);
			// 
			// menuItemEraserSizeLarge
			// 
			this.menuItemEraserSizeLarge.Index      = 2;
			this.menuItemEraserSizeLarge.Text       = "&Large";
			this.menuItemEraserSizeLarge.RadioCheck = true;
			this.menuItemEraserSizeLarge.Click     += new System.EventHandler(this.MenuItemEraserSize_Click);
		}

		/// <summary>
		/// Initializes the toolbar's modes and checks the appropriate menu items.
		/// </summary>
		private void InitializeModes()
		{
			//
			// Attributes
			//
			m_penAttributes         = new Microsoft.Ink.DrawingAttributes();
			m_highlighterAttributes = new Microsoft.Ink.DrawingAttributes();
			m_eraserAttributes      = new ErasingAttributes();
			
			//
			// Pen Attributes
			//
			m_penAttributes.AntiAliased  = true;
			m_penAttributes.Color        = Color.Black;
			m_penAttributes.Width        = penSizeMedium;
			m_penAttributes.Height       = m_penAttributes.Width;
			m_penAttributes.FitToCurve   = true;
			m_penAttributes.PenTip       = PenTip.Ball;
			m_penAttributes.Transparency = 0;

			//Check color menu
			foreach (ImageMenuItem item in this.menuItemPenColors)
			{
				if (m_penAttributes.Color.Name == StripAmpersandFromMenuText(item.Text))
					item.Checked = true;
				else
					item.Checked = false;
			}

			//Check size menu
			foreach (MenuItem item in this.menuItemPenSizes)
			{
				if (item == menuItemPenSizes[1])
					item.Checked = true;
				else
					item.Checked = false;
			}

			//Check pen tip menu
			this.menuItemPenTipBall.Checked = true;

			//
			// Highlighter Attributes
			//
			m_highlighterAttributes.AntiAliased  = true;
			m_highlighterAttributes.Color        = Color.Yellow;
			m_highlighterAttributes.Width        = penSizeThick;
			m_highlighterAttributes.Height       = 600;
			m_highlighterAttributes.PenTip       = PenTip.Rectangle;
			m_highlighterAttributes.Transparency = Convert.ToByte(255 * 0.7); //70%
			

			// Check highlighter color menu
			foreach (MenuItem item in this.menuItemHighlighterColors)
			{
				if (m_highlighterAttributes.Color.Name == StripAmpersandFromMenuText(item.Text))
					item.Checked = true;
				else
					item.Checked = false;
			}

			//
			// Eraser Attributes
			//
			m_eraserAttributes.Mode = InkOverlayEraserMode.StrokeErase;
			m_eraserAttributes.Size = InkToolBar.eraserSizeMedium;

			// Check eraser menu items
			menuItemEraserModeStroke.Checked = true;
			menuItemEraserSizeMedium.Checked = true;

			// Disable size menu
			this.menuItemEraserSize.Enabled  = false;

			// Allow Point Eraser
			m_allowPointEraser = true;
			
			// Set default attributes
			if (Mode == InkToolBarMode.Highlighter)
				SetInkDrawingAttributes(m_highlighterAttributes);
			else
				SetInkDrawingAttributes(m_penAttributes);
		}
		
	
		#region Component Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(InkToolBar));
			this.m_btnPen = new System.Windows.Forms.ToolBarButton();
			this.m_menuPen = new System.Windows.Forms.ContextMenu();
			this.m_btnHighlighter = new System.Windows.Forms.ToolBarButton();
			this.m_menuHighlighter = new System.Windows.Forms.ContextMenu();
			this.m_btnEraser = new System.Windows.Forms.ToolBarButton();
			this.m_menuEraser = new System.Windows.Forms.ContextMenu();
			this.m_btnLasso = new System.Windows.Forms.ToolBarButton();
			this.m_sizeImages = new System.Windows.Forms.ImageList(this.components);
			this.m_colorImages = new System.Windows.Forms.ImageList(this.components);
			this.m_imagesAlpha = new System.Windows.Forms.ImageList(this.components);
			// 
			// m_btnPen
			// 
			this.m_btnPen.DropDownMenu = this.m_menuPen;
			this.m_btnPen.ImageIndex = 0;
			this.m_btnPen.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
			this.m_btnPen.ToolTipText = "Pen";
			// 
			// m_btnHighlighter
			// 
			this.m_btnHighlighter.DropDownMenu = this.m_menuHighlighter;
			this.m_btnHighlighter.ImageIndex = 1;
			this.m_btnHighlighter.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
			this.m_btnHighlighter.ToolTipText = "Highlighter";
			// 
			// m_btnEraser
			// 
			this.m_btnEraser.DropDownMenu = this.m_menuEraser;
			this.m_btnEraser.ImageIndex = 2;
			this.m_btnEraser.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
			this.m_btnEraser.ToolTipText = "Eraser";
			// 
			// m_btnLasso
			// 
			this.m_btnLasso.ImageIndex = 3;
			this.m_btnLasso.ToolTipText = "Lasso";
			this.m_btnLasso.Visible = false;
			// 
			// m_sizeImages
			// 
			this.m_sizeImages.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
			this.m_sizeImages.ImageSize = new System.Drawing.Size(80, 17);
			this.m_sizeImages.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("m_sizeImages.ImageStream")));
			this.m_sizeImages.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// m_colorImages
			// 
			this.m_colorImages.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
			this.m_colorImages.ImageSize = new System.Drawing.Size(24, 17);
			this.m_colorImages.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("m_colorImages.ImageStream")));
			this.m_colorImages.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// m_imagesAlpha
			// 
			this.m_imagesAlpha.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
			this.m_imagesAlpha.ImageSize = new System.Drawing.Size(24, 24);
			this.m_imagesAlpha.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("m_imagesAlpha.ImageStream")));
			this.m_imagesAlpha.TransparentColor = System.Drawing.Color.Red;
			// 
			// InkToolBar
			// 
			this.AccessibleRole = System.Windows.Forms.AccessibleRole.ToolBar;
			this.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
			this.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																			   this.m_btnPen,
																			   this.m_btnHighlighter,
																			   this.m_btnEraser,
																			   this.m_btnLasso});
			this.ButtonSize = new System.Drawing.Size(31, 30);
			this.Divider = false;
			this.ImageList = this.m_imagesAlpha;
			this.Size = new System.Drawing.Size(100, 31);
			this.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.ToolBarButtonClicked);

		}
		#endregion
		
		#region Overridden Base Class Properties
		/// <summary>
		/// Gets or sets the accessible role of the control.
		/// </summary>
		/// <remarks>Overridden to change the default value for the AccessibleRole property</remarks>
		[DefaultValue(AccessibleRole.ToolBar)]
		public new System.Windows.Forms.AccessibleRole AccessibleRole
		{
			get { return base.AccessibleRole;  }
			set { base.AccessibleRole = value; }
		}	

		/// <summary>
		/// Gets the collection of System.Windows.Forms.ToolBarButton controls assigned to the 
		/// toolbar control.
		/// </summary>
		/// <remarks>Overridden to remove the Buttons property from the properties window</remarks>
		[Browsable(false)]
		public new ToolBar.ToolBarButtonCollection Buttons
		{
			get { return base.Buttons; }
		}

		/// <summary>
		/// Gets or sets the collection of images available to the toolbar button controls.
		/// </summary>
		/// <remarks>Overridden to remove the ImageList property from the properties window</remarks> 
		[Browsable(false)]
		public new System.Windows.Forms.ImageList ImageList
		{
			get { return base.ImageList; }
			set { base.ImageList = value; }
		}

		/// <summary>
		/// Gets or sets the value indicating whether drop-down buttons on a toolbar display down arrows.
		/// </summary>
		/// <remarks>Overridden to change the default value for the DropDownArrows property</remarks>
		[DefaultValue(true)]
		public new bool DropDownArrows
		{
			get { return base.DropDownArrows;  }
			set { base.DropDownArrows = value; }
		}

		/// <summary>
		///  Gets or sets the value that determines the appearance of a toolbar control and its buttons. 
		/// </summary>
		/// <remarks>Overridden to change the default value for the Appearance property</remarks>
		[DefaultValue(ToolBarAppearance.Flat)]
		public new ToolBarAppearance Appearance
		{
			get { return base.Appearance;  }
			set { base.Appearance = value; }
		}

		/// <summary>
		///  Gets or sets a value indicating whether the toolbar displays a tooltip for each button. 
		/// </summary>
		/// <remarks>Overridden to change the default value for the ShowTooltips property</remarks>
		[DefaultValue(true)]
		public new bool ShowToolTips
		{
			get { return base.ShowToolTips;  }
			set { base.ShowToolTips = value; }
		}

		#endregion

		#region Event Handlers
		/// <summary>
		/// Raises the <c>SettingsChanged</c> event.
		/// </summary>
		/// <remarks>
		/// The <c>SettingsChanged</c> event is raised when pen or highlighter settings change such as 
		/// color.
		/// </remarks>
		protected virtual void OnSettingsChanged()
		{
			// Fire event to any subscribers
			if (null != SettingsChanged)
			{
				SettingsChanged(this, new EventArgs());
			}
		}

		/// <summary>
		/// Raises the <c>ModeChanged</c> event.
		/// </summary>
		/// <remarks>
		/// The <c>ModeChanged</c> event is raised when the currently selected tool changes.
		/// </remarks>
		protected virtual void OnModeChanged()
		{
			//
			// Fire event to any subscribers
			//
			if (ModeChanged != null)
			{
				ModeChanged(this, new EventArgs());
			}
		}

		/// <summary>
		/// Raises the <c>SettingsDialogVisibilityChanged</c> event.
		/// </summary>
		/// <remarks>
		/// The <c>SettingsDialogVisibilityChanged</c> event is raised when the Settings Dialog is opened or closed.
		/// </remarks>
		protected virtual void OnSettingsDialogVisibleChanged(object sender, System.EventArgs e)
		{
			if (SettingsDialogVisibleChanged != null)
			{
				SettingsDialogVisibleChanged(sender, e);
			}
		}

		private void OnSettingsDialogVisibilityChanged(object sender, System.EventArgs e)
		{
			OnSettingsDialogVisibleChanged(sender, e);
		}

		#endregion
		
		#region Properties
		/// <summary>
		/// Indicates whether the Settings Dialog is open.
		/// </summary>
		[Browsable(false)]
		public bool SettingsDialogVisible
		{
			get
			{
				if (m_settingsDialog == null)
					return false;
				else
					return m_settingsDialog.Visible;
			}
		}

		/// <summary>
		/// Returns the drawing attributes for the tool selected. (Only applies to Pen and 
		/// Highlighter modes.)
		/// </summary>
		/// <value>
		/// The <c>Microsoft.Ink.DrawingAttributes</c> that contain settings for the Pen or Highlighter.
		/// </value>
		/// <remarks>
		/// This property is most often accessed when handling the <c>SettingsChanged</c> event.
		/// </remarks>
		[Browsable(false)]
		public Microsoft.Ink.DrawingAttributes InkDrawingAttributes
		{
			get { return this.m_drawingAttributes; }
		}

		/// <summary>
		/// Sets the default drawing attributes for the pen tool.  Should only be used for initialization.
		/// </summary>
		[Category("Ink")]
		[Description("Default drawing attributes used by the pen tool")]
		[Browsable(false)] // Temporary
		public Microsoft.Ink.DrawingAttributes DefaultPenSettings
		{
			get { return m_penAttributes; }
			set
			{
				m_penAttributes = value;
				UpdatePenMenus();

				//Set default attributes
				if (Mode == InkToolBarMode.Pen)
					SetInkDrawingAttributes(m_penAttributes);
			}
		}

		/// <summary>
		/// Sets the default drawing attributes for the highlighter tool.  Should only be used for initialization.
		/// </summary>
		[Category("Ink")]
		[Description("Default drawing attributes used by the highlighter tool")]
		[Browsable(false)] // Temporary
		public Microsoft.Ink.DrawingAttributes DefaultHighlighterSettings
		{
			get { return m_highlighterAttributes; }
			set
			{
				m_highlighterAttributes = value;
				UpdateHighlighterMenus();

				if (Mode == InkToolBarMode.Highlighter)
					SetInkDrawingAttributes(m_highlighterAttributes);
			}
		}

		/// <summary>
		/// Gets the eraser attributes.
		/// </summary>
		/// <value>
		/// The <c>EraserAttributes</c> class contain settings for the Eraser tool.
		/// </value>
		/// <remarks>
		/// This property is most often accessed when handling the <c>ModeChanged</c> event.
		/// It contains settings mode the eraser mode and width.
		/// </remarks>
		[Browsable(false)]
		public ErasingAttributes EraserAttributes
		{
			get { return this.m_eraserAttributes; }
		}

		/// <summary>
		/// Indicates whether highlighter should render using alpha transparency or
		/// use a MaskPen RasterOperation.
		/// </summary>
		[Category("Behavior")]
		[Description("Indicates whether highlighter should render using alpha transparency or use a MaskPen RasterOperation.")]
		[DefaultValue(false)]
		public bool UseRasterOperationForHighlighter
		{
			get { return this.m_useRasterOpForHighlighter;  }
			set 
			{ 
				this.m_useRasterOpForHighlighter	 = value;
				m_highlighterAttributes.Transparency = Convert.ToByte(255 * 0.7); //70%

				if (value)
					m_highlighterAttributes.RasterOperation = RasterOperation.MaskPen;
				else
					m_highlighterAttributes.RasterOperation = RasterOperation.CopyPen;
			}
		}

		/// <summary>
		/// Gets or sets the <c>Mode</c> of the toolbar.
		/// </summary>
		/// <value>
		/// One of the <c>InkToolBarMode</c> values.  The default is <c>InkToolBarMode.Pen</c>.
		/// </value>
		/// <remarks>
		/// The <c>Mode</c> property determines which Ink tool is selected on the toolbar.  When a
		/// <c>Mode</c> changes, the <c>ModeChanged</c> event is fired.
		/// </remarks>
		[Category("Behavior")]
		[Description("Indicates the default tool.")]
		[DefaultValue(InkToolBarMode.Pen)]
		public InkToolBarMode Mode
		{
			get { return m_mode;  }
			set 
			{ 
				if (m_mode != value)
				{
					m_mode = value;
					OnModeChanged();
				}

				switch (value)
				{
					case InkToolBarMode.Pen:
						SetInkDrawingAttributes(this.m_penAttributes);
						break;
					case InkToolBarMode.Highlighter:
						SetInkDrawingAttributes(this.m_highlighterAttributes);
						break;
					case InkToolBarMode.Eraser:
					case InkToolBarMode.Lasso:
					default:
						break;
				}				
			}
		}

		/// <summary>
		/// Gets or sets whether point erasing is allowed.
		/// </summary>
		[Category("Behavior")]
		[Description("Indicates whether point erasing is allowed.")]
		[DefaultValue(true)]
		public bool AllowPointEraser
		{
			get { return m_allowPointEraser;  }
			set 
			{ 
				if (m_allowPointEraser != value)
				{
					m_allowPointEraser = value;
					if (value)
                        m_btnEraser.Style = ToolBarButtonStyle.DropDownButton;
					else
						m_btnEraser.Style = ToolBarButtonStyle.PushButton;
				}
			}
		}
	
		/// <summary>
		/// Sets the default drawing attributes.
		/// </summary>
		/// <param name="drawingAttributes"></param>
		private void SetInkDrawingAttributes(Microsoft.Ink.DrawingAttributes drawingAttributes)
		{
			this.m_drawingAttributes = drawingAttributes;
			OnSettingsChanged();
		}

		#endregion
		
		#region Internal Event Handlers
		/// <summary>
		/// Event handler for the <c>ToolBar.ButtonClick</c> event.
		/// </summary>
		/// <param name="sender">Object that invoked the event.</param>
		/// <param name="e">A <c>ToolBarButtonClickEventArgs</c> that contains the event data.</param>
		private void ToolBarButtonClicked(Object sender, ToolBarButtonClickEventArgs e)
		{
			switch (this.Buttons.IndexOf(e.Button))
			{
				case 0:
					Mode = InkToolBarMode.Pen;
					break;
				case 1:
					Mode = InkToolBarMode.Highlighter;
					break;
				case 2:
					Mode = InkToolBarMode.Eraser;
					break;
				case 3:
					Mode = InkToolBarMode.Lasso;
					break;
				default:
					break;
			}
		}
		
		/// <summary>
		/// Event handler for the <c>MenuItem.Click</c> event from the Pen-Color menus.
		/// </summary>
		/// <param name="sender">Object that invoked the event.</param>
		/// <param name="e">An <c>EventArgs</c> that contains the event data.</param>
		/// <remarks>
		/// By setting the <c>Mode</c> at the end of the method.  The <c>ModeChanged</c> event will be 
		/// fired if needed.
		/// </remarks>
		private void MenuItemPenColors_Click(object sender, System.EventArgs e)
		{
			//Get the menu item's index
			int index = ((ImageMenuItem)sender).Index;
			
			// Obtain the menu text without the shortcut ampersand: '&'.
			string name = StripAmpersandFromMenuText(menuItemPenColors[index].Text);
						
			//Update pen attributes' color
			m_penAttributes.Color = Color.FromName(name);

			//Check mark the relative item
			foreach(ImageMenuItem i in menuItemPenColors)
				i.Checked = (index == i.Index);

			//Set the mode
			Mode = InkToolBarMode.Pen;
		}

		/// <summary>
		/// Event handler for the <c>MenuItem.Click</c> event from the Pen-Size menus.
		/// </summary>
		/// <param name="sender">Object that invoked the event.</param>
		/// <param name="e">An <c>EventArgs</c> that contains the event data.</param>
		/// <remarks>
		/// By setting the <c>Mode</c> at the end of the method.  The <c>ModeChanged</c> event will be 
		/// fired if needed.
		/// </remarks>
		private void MenuItemPenSizes_Click(object sender, System.EventArgs e)
		{
			//Get the menu item's index
			int index = ((ImageMenuItem)sender).Index;

			//Update pen attributes' width & height
			switch (index)
			{
				case 0:
					m_penAttributes.Height = m_penAttributes.Width = penSizeFine;
					break;
				case 1:
					m_penAttributes.Height = m_penAttributes.Width = penSizeMedium;
					break;
				case 2:
					m_penAttributes.Height = m_penAttributes.Width = penSizeThick;
					break;
				default:
					break;
			}

			//Check mark the relative item
			foreach(ImageMenuItem i in menuItemPenSizes)
				i.Checked = (index == i.Index);

			//Set the mode
			Mode = InkToolBarMode.Pen;
		}

		/// <summary>
		/// Event handler for the <c>MenuItem.Click</c> event from the Pen-Tip menus.
		/// </summary>
		/// <param name="sender">Object that invoked the event.</param>
		/// <param name="e">An <c>EventArgs</c> that contains the event data.</param>
		/// <remarks>
		/// By setting the <c>Mode</c> at the end of the method.  The <c>ModeChanged</c> event will be 
		/// fired if needed.
		/// </remarks>
		private void MenuItemPenTip_Click(object sender, System.EventArgs e)
		{
			if (sender == menuItemPenTipBall)
			{
				this.m_penAttributes.PenTip          = PenTip.Ball;
				this.menuItemPenTipBall.Checked      = true;
				this.menuItemPenTipRectangle.Checked = false;
			}
			else
			{	//Must be menuItemTipRectangle
				this.m_penAttributes.PenTip          = PenTip.Rectangle;
				this.menuItemPenTipRectangle.Checked = true;
				this.menuItemPenTipBall.Checked      = false;
			}

			Mode = InkToolBarMode.Pen;
		}

		/// <summary>
		/// Event handler for the <c>MenuItem.Click</c> event for opening the <c>SettingsDialog</c>.
		/// </summary>
		/// <param name="sender">Object that invoked the event.</param>
		/// <param name="e">An <c>EventArgs</c> that contains the event data.</param>
		/// <remarks>
		/// Displays the <c>SettingsDialog</c>, updating any attributes that might have changed for the pen.
		/// <para>
		/// By setting the <c>Mode</c> at the end of the method.  The <c>ModeChanged</c> event will be 
		/// fired if needed.
		/// </para>
		/// </remarks>
		private void MenuItemPenSettings_Click(object sender, System.EventArgs e)
		{
			//
			// Display the settings dialog, updating any attributes that might have
			// changed for the pen.
			//
			m_settingsDialog				 = new SettingsDialog(m_penAttributes.Clone());
			m_settingsDialog.VisibleChanged += new System.EventHandler(OnSettingsDialogVisibilityChanged);
			m_settingsDialog.Text			 = "Pen Settings";
			
			if (m_settingsDialog.ShowDialog(this.Parent) == DialogResult.OK)
			{
				m_penAttributes = m_settingsDialog.InkDrawingAttributes;

				UpdatePenMenus();
			}

			// Unsubscribe from the VisibleChanged event.
			m_settingsDialog.VisibleChanged -= new System.EventHandler(OnSettingsDialogVisibilityChanged);
			
			Mode = InkToolBarMode.Pen;
		}

		/// <summary>
		/// Updates the pen menus after pen settings have changed.
		/// </summary>
		private void UpdatePenMenus()
		{
			foreach (ImageMenuItem i in menuItemPenColors)
			{
				i.Checked = (m_penAttributes.Color.Name == StripAmpersandFromMenuText(i.Text));
			}

			menuItemPenTipBall.Checked      = (m_penAttributes.PenTip == PenTip.Ball);
			menuItemPenTipRectangle.Checked = (m_penAttributes.PenTip == PenTip.Rectangle);

			//Check the appropriate size menu depending on the tip used.
			if (m_penAttributes.PenTip == PenTip.Ball)
			{
				menuItemPenSizes[0].Checked = (m_penAttributes.Width == penSizeFine);
				menuItemPenSizes[1].Checked = (m_penAttributes.Width == penSizeMedium);
				menuItemPenSizes[2].Checked = (m_penAttributes.Width == penSizeThick);
			}
			else
			{
				menuItemPenSizes[0].Checked = (m_penAttributes.Width  == penSizeFine)  &&
											  (m_penAttributes.Height == penSizeFine);
				menuItemPenSizes[1].Checked = (m_penAttributes.Width == penSizeMedium) &&
											  (m_penAttributes.Height == penSizeMedium); 
				menuItemPenSizes[2].Checked = (m_penAttributes.Width == penSizeThick)  &&
											  (m_penAttributes.Height == penSizeThick);
			}
		}

		/// <summary>
		/// Event handler for the <c>MenuItem.Click</c> event from the Highlighter-Color menus.
		/// </summary>
		/// <param name="sender">Object that invoked the event.</param>
		/// <param name="e">An <c>EventArgs</c> that contains the event data.</param>
		/// <remarks>
		/// By setting the <c>Mode</c> at the end of the method.  The <c>ModeChanged</c> event will be 
		/// fired if needed. 
		///	</remarks>
		private void MenuItemHighlighterColors_Click(object sender, System.EventArgs e)
		{
			//Get the menu item's index
			int index = ((ImageMenuItem)sender).Index;

			// Obtain the menu text without the shortcut ampersand: '&'.
			string name = StripAmpersandFromMenuText(menuItemHighlighterColors[index].Text);
						
			//Update highlighter attributes' color
			this.m_highlighterAttributes.Color = Color.FromName(name);

			//Check mark the relative item
			foreach(ImageMenuItem i in menuItemHighlighterColors)
				i.Checked = (index == i.Index);

			//Set the mode
			Mode = InkToolBarMode.Highlighter;
		}

		/// <summary>
		/// Event handler for the <c>MenuItem.Click</c> event for opening the <c>SettingsDialog</c>.
		/// </summary>
		/// <param name="sender">Object that invoked the event.</param>
		/// <param name="e">An <c>EventArgs</c> that contains the event data.</param>
		/// <remarks>
		/// Displays the <c>SettingsDialog</c>, updating any attributes that might have changed for the 
		/// highlighter.
		/// <para>
		/// By setting the <c>Mode</c> at the end of the method.  The <c>ModeChanged</c> event will be 
		/// fired if needed.
		/// </para>
		/// </remarks>
		private void MenuItemHighlighterSettings_Click(object sender, System.EventArgs e)
		{
			//
			// Display the settings dialog, updating any attributes that might have
			// changed for the highlighter.
			//
			m_settingsDialog				 = new SettingsDialog(m_highlighterAttributes.Clone());
			m_settingsDialog.VisibleChanged += new System.EventHandler(OnSettingsDialogVisibilityChanged);
			m_settingsDialog.Text			 = "Highlighter Settings";

			if (m_settingsDialog.ShowDialog(this.Parent) == DialogResult.OK)
			{
				m_highlighterAttributes = m_settingsDialog.InkDrawingAttributes;
				
				UpdateHighlighterMenus();				
			}
			// Unsubscribe from the VisibleChanged event.
			m_settingsDialog.VisibleChanged -= new System.EventHandler(OnSettingsDialogVisibilityChanged);


			Mode = InkToolBarMode.Highlighter;
		}

		/// <summary>
		/// Updates the highlighter color menus after settings are changed using the <c>SettingsDialog</c>.
		/// </summary>
		private void UpdateHighlighterMenus()
		{
			foreach (ImageMenuItem i in menuItemHighlighterColors)
				i.Checked = (m_highlighterAttributes.Color.Name == StripAmpersandFromMenuText(i.Text));
		}

		/// <summary>
		/// Event handler for the <c>MenuItem.Click</c> event for changing the eraser's mode.
		/// </summary>
		/// <param name="sender">Object that invoked the event.</param>
		/// <param name="e">An <c>EventArgs</c> that contains the event data.</param>
		/// <remarks>
		/// By setting the <c>Mode</c> at the end of the method.  The <c>ModeChanged</c> event will be 
		/// fired if needed.  Similarly calling <see cref="OnSettingsChanged"/> will raise the
		/// <c>SettingsChanged</c> event.
		/// </remarks>
		private void MenuItemEraserMode_Click(object sender, System.EventArgs e)
		{
			if (sender == menuItemEraserModeStroke)
			{
				this.m_eraserAttributes.Mode          = InkOverlayEraserMode.StrokeErase;
				this.menuItemEraserModeStroke.Checked = true;
				this.menuItemEraserModePoint.Checked  = false;

				//Disable size menu
				this.menuItemEraserSize.Enabled       = false;
			}
			else
			{	//Must be menuItemEraserModePoint
				this.m_eraserAttributes.Mode          = InkOverlayEraserMode.PointErase;
				this.menuItemEraserModeStroke.Checked = false;
				this.menuItemEraserModePoint.Checked  = true;	
			
				//Enable size menu
				this.menuItemEraserSize.Enabled       = true;
			}

			Mode = InkToolBarMode.Eraser;
			OnSettingsChanged();			
		}
		
		/// <summary>
		/// Event handler for the <c>MenuItem.Click</c> event for changing the eraser's size when
		/// the eraser's mode is set to Point.
		/// </summary>
		/// <param name="sender">Object that invoked the event.</param>
		/// <param name="e">An <c>EventArgs</c> that contains the event data.</param>
		/// <remarks>
		/// By setting the <c>Mode</c> at the end of the method.  The <c>ModeChanged</c> event will be 
		/// fired if needed.  Similarly calling <see cref="OnSettingsChanged"/> will raise the
		/// <c>SettingsChanged</c> event.
		/// </remarks>
		private void MenuItemEraserSize_Click(object sender, System.EventArgs e)
		{
			if (sender == menuItemEraserSizeSmall)
			{
				this.m_eraserAttributes.Size         = InkToolBar.eraserSizeSmall;
				this.menuItemEraserSizeSmall.Checked  = true;
				this.menuItemEraserSizeMedium.Checked = false;
				this.menuItemEraserSizeLarge.Checked  = false;
			}
			else
				if (sender == menuItemEraserSizeMedium)
			{
				this.m_eraserAttributes.Size         = InkToolBar.eraserSizeMedium;
				this.menuItemEraserSizeSmall.Checked  = false;
				this.menuItemEraserSizeMedium.Checked = true;
				this.menuItemEraserSizeLarge.Checked  = false;
			}
			else 
			{	//Must be large
				this.m_eraserAttributes.Size         = InkToolBar.eraserSizeLarge;
				this.menuItemEraserSizeSmall.Checked  = false;
				this.menuItemEraserSizeMedium.Checked = false;
				this.menuItemEraserSizeLarge.Checked  = true;
			}

			Mode = InkToolBarMode.Eraser;
			OnSettingsChanged();			
		}

		/// <summary>
		/// Helper method to remove apsersand character from menu text for Color.FromName()
		/// </summary>
		/// <param name="menuText">Menu text of a color</param>
		/// <returns>Menu text without ampersand character</returns>
		private string StripAmpersandFromMenuText(string menuText)
		{
			// Obtain the menu text without the shortcut ampersand: '&'.
			string text		   = menuText;
			int idxOfAmpersand = text.IndexOf('&');
			if (idxOfAmpersand >= 0)
				text = menuText.Remove(idxOfAmpersand, 1);

			return text;
		}
		#endregion
		
		/// <summary>
		/// Provides a utility dialog to edit drawing attributes.
		/// </summary>
		/// <param name="drawingAttributes">The Microsoft.Ink.DrawingAttributes to edit.</param>
		public static void EditDrawingAttributes(Microsoft.Ink.DrawingAttributes drawingAttributes)
		{
			SettingsDialog s  = new SettingsDialog(drawingAttributes.Clone());
									
			if (s.ShowDialog() == DialogResult.OK)
			{
				drawingAttributes = s.InkDrawingAttributes;
			}
		}
	}
}
